package com.wufan.day02;

/**
 * 定义int 10元素数组，赋予两位随机数
 * 求max，min，sum，average，输出
 * @author SongWufan
 * @date 2021/3/5 11:50
 */
public class ArrayTest7 {
    public static void main(String[] args) {
        int[] arr = new int[10];

        for (int i = 0; i < arr.length; i++){
            arr[i] = (int) (Math.random() * (99 - 10 + 1) + 10);
        }
        //遍历
        for (int i = 0; i < arr.length; i++){
            System.out.print(arr[i]+" ");
        }
        System.out.println();
        //求数组最大值
        int maxValue = arr[0];
        for (int i = 0; i < arr.length; i++){
            if (maxValue < arr[i]){
                maxValue = arr[i];
            }
        }
        System.out.println("最大值："+maxValue);
        //求最小值
        int minValue = arr[0];
        for (int i = 0; i < arr.length; i++){
            if (minValue > arr[i]){
                minValue = arr[i];
            }
        }
        System.out.println("最小值："+minValue);
        //求总和
        int sum = 0;
        for (int i = 0; i < arr.length; i++){
            sum += arr[i];
        }
        System.out.println("总和："+sum);
        //求平均数
        int avgValue = sum / arr.length;
        System.out.println("平均数："+avgValue);
    }
}
